package com.xiaoxiong.mami.dao.mapperImpl;

import com.xiaoxiong.mami.dao.daomain.Cart;
import com.xiaoxiong.mami.dao.mapper.CartMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by Administrator on 2017/7/31.
 */
@Mapper
public interface CartMapperImpl extends CartMapper {




    @Insert("insert into cart (userid,goodsId,batchNumber,total,status,createTime,updateTime)" +
            "values (#{userId},#{goodsId},#{batchNumber},#{total},'1',now(),now())")
    public int insertCart(Cart cart);


   @Select("select * from cart where goodsId = #{goodsId} and userid = #{userid} and status = '1'")
    public Cart queryCartByGoodsId(@Param("goodsId")String goodsId,@Param("userid") String userid);


    @Select("select * from cart where userid = #{userid} and  status = '1' order by goodsId,createTime desc ")
    public List<Cart> getCartListByUserId(String userid);


    @Update("UPDATE cart SET total=#{total} where goodsid =#{goodsid} and userid = #{userid}")
    public int updateCartTotal(@Param("userid") String userid,@Param("goodsid")String goodsid,@Param("total")String total);

    @Update("UPDATE cart SET status=#{status} where goodsid =#{goodsid} and userid = #{userid}")
    public int updateCartStatus(@Param("userid") String userid,@Param("goodsid")String goodsid,@Param("status")String status);


    @Delete("<script>"
            + "delete  FROM cart WHERE userid = #{userid} and goodsId IN "
            + "<foreach item='item' index='index' collection='goodsIds' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>")
    public void deleteGoodsByCartsForFinish(@Param("userid")String userid,@Param("goodsIds") List<String> goodsIds);

}
